package com.mhy.ssm.mapper;

import com.mhy.ssm.pojo.Order;
import com.mhy.ssm.pojo.OrderDetail;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface OrderMapper {

    @Select("select * from orderdetail where id = #{id}")
    OrderDetail selectById(Integer id);
    @Select("select * from orders where id = #{id}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "user_id", property = "userId"),
            @Result(column = "user_id", property = "user",
                    one = @One(select = "com.mhy.ssm.mapper.UserMapper.selectById2", fetchType = FetchType.LAZY))
    })
    Order selectById2(Integer id);

    @Select("select * from orders where user_id = #{user_id}")
    List<Order> getOrderByUserId(Integer userId);
}
